package job

import (
	"gitee.com/gomod/utils/logger"
	"github.com/robfig/cron/v3"
	"learn-land-crawler/app/service"
	"time"
)

var c *cron.Cron

func InitTasks() {
	local, _ := time.LoadLocation("Asia/Shanghai")
	c = cron.New(cron.WithLocation(local), cron.WithSeconds())
	_, err := c.AddFunc("0 50 16 * * *", func() {
		logger.Info.Println("start service.Save600XuePage")
		service.Save600XuePage()
	})
	if err != nil {
		panic(err)
	}
	_, err = c.AddFunc("0 05 17 * * *", func() {
		logger.Info.Println("start service.Save600XudDetail")
		service.Save600XudDetail(nil)
	})
	if err != nil {
		panic(err)
	}
	_, err = c.AddFunc("0 35 17 * * *", func() {
		logger.Info.Println("start service.Save600XudDownload")
		service.Save600XudDownload(8)
	})
	if err != nil {
		panic(err)
	}

	c.Start()
}
